package com.gxa.meiye.admin.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.platform.mapper.UserMapper;
import com.gxa.meiye.admin.platform.pojo.vo.UpdateUserStatusVo;
import com.gxa.meiye.admin.platform.pojo.vo.UserVo;
import com.gxa.meiye.admin.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserVo> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserVo> selectUserList() {
        List<UserVo> userVos = userMapper.selectList(null);
        return userVos;
    }

    @Override
    public void updateStatus(UpdateUserStatusVo userVo) {
        LambdaUpdateWrapper<UserVo> userVoLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        userVoLambdaUpdateWrapper.eq(UserVo::getId,userVo.getId());
        if(userVo.getStatus()!=0) {
            userVoLambdaUpdateWrapper.set(UserVo::getStatus, 0);
        }else {
            userVoLambdaUpdateWrapper.set(UserVo::getStatus, 1);
        }
        userMapper.update(null,userVoLambdaUpdateWrapper);
    }

    @Override
    public List<UserVo> selectUsers(String select) {
        LambdaQueryWrapper<UserVo> userVoLambdaQueryWrapper = Wrappers.lambdaQuery();
        userVoLambdaQueryWrapper.like(UserVo::getId,"%"+select+"%").or().like(UserVo::getName,"%"+select+"%")
                .or().like(UserVo::getPhone,"%"+select+"%");
        List<UserVo> userVos = userMapper.selectList(userVoLambdaQueryWrapper);
        return userVos;
    }
}
